<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<div class="page-breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="fa fa-home"></i>
            <a href="#">Home</a>
        </li>
        <li class="active">使用帮助</li>
    </ul>
</div>
<!-- Page Body -->
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-header bordered-bottom bordered-themeprimary">
                    <i class="widget-icon fa fa-tasks themeprimary"></i>
                    <span class="widget-caption themeprimary">Oauth 使用说明</span>
                </div>
                <div class="widget-body">
                	<div class="orders-container padding-bottom-5">
                       <ul class="orders-list">
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>1. 先注册应用</h4>
                                  <pre>
http://localhost:10000/main#!client/add
会生成client_id和client_secret 这两个以后会用到
client_id               3c65d9602a6a44daaa80e3609c4a2be6    <b>应用id</b>
client_secret           28f190d727d645a890a36258c405afd1    <b>应用secret</b>                                               
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>2. 请求授权码</h4>
                                  <pre>
http://localhost:10000/authorize?client_id=3c65d9602a6a44daaa80e3609c4a2be6&response_type=code&username=admin&password=123&redirect_uri=http://baidu.com
参数说明
client_id               <b>应用id</b>
response_type           <b>返回授权码的标识</b>
redirect_uri            <b>回调地址</b>
上面的网站会打开oauth server的用户登录页面。用户输入正确的用户名和密码以POST方式提交后会重定向到用户所填的回调地址并在地址后携带授权码.
请求成功后会返回如下的页面:
http://baidu.com?code=0810ea2a451736796cadfcc928e9a82f
这里code=0810ea2a451736796cadfcc928e9a82f <b>即授权码</b>
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>3. 换取 accessToken (POST操作)</h4>
                                  <pre>
以POST方式提交到http://localhost:10000/accessToken,最终返回accessToken
具体参数详情为:
client_id       3c65d9602a6a44daaa80e3609c4a2be6            <b>应用id</b>
client_secret   28f190d727d645a890a36258c405afd1            <b>应用secret</b>
grant_type      authorization_code                          <b>用于传递授权码的参数名authorization_code</b>
code            0810ea2a451736796cadfcc928e9a82f            <b>用户登录授权后的授权码</b>
redirect_uri    http://baidu.com                            <b>回调地址</b>
response_type   token                                       <b>标注通过token身份验证</b>
最终返回如下数据
{"expires_in":3600,"access_token":"8af96f8ce8609602c5bc73969e397eac"}
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>4. 测试 accessToken</h4>
                                  <pre>
http://localhost:10000/api/v1/userinfo/checkAccessToken?access_token=223ae05dfbb0794396fb60a0960c197e
测试ok的话返回用户名信息,access_token=223ae05dfbb0794396fb60a0960c197e为上一步获取的access_token
<b>注：其中的参数名不要随意更改，固定写法。</b>
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>5. 测试 notCheckAccessToken</h4>
                                  <pre>
http://localhost:10000/api/v1/userinfo/notCheckAccessToken?access_token=223ae05dfbb0794396fb60a0960c197e
测试ok的话返回用户名信息,access_token=223ae05dfbb0794396fb60a0960c197e为上一步获取的access_token
<b>注：其中的参数名不要随意更改，固定写法。</b>
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           <li class="order-item">
                               <div class="row">
                                   <div class="col-md-12">
                                       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 item-left">
                                           <div class="item-booker">
                                               <h4>5. 客户端测试</h4>
                                  <pre>
public static void main(String[] args) throws Exception {
	String url = "http://localhost:10000/authorize?client_id=ce59f4922c8f400cbc8bdcd27512f1b8&response_type=code&username=Admin&password=shishun156&redirect_uri=http://115.28.66.183/ibsm/login.html";
	System.out.println(EntityUtils.toString(
			new HttpClientFactory().execute(new MyHttpConfig().method(HttpMethods.GET).uri(url)).getEntity(),
			Response.CHART));

	url = "http://localhost:10000/accessToken";
	Map<String, Object> param = new HashMap<String, Object>();
	{
		param.put("client_id", "ce59f4922c8f400cbc8bdcd27512f1b8");
		param.put("client_secret", "cd08aa85df3749c180e6a61d885e0e12");
		param.put("grant_type", "authorization_code");
		param.put("code", "db280e7f552ab1c69bceba45b40bb020");
		param.put("redirect_uri", "http://115.28.66.183/ibsm/login.html");
		param.put("response_type", "token");
	}

	HttpResponse response = new HttpClientFactory()
			.execute(new MyHttpConfig().method(HttpMethods.POST).map(param).uri(url));
	String json = EntityUtils.toString(response.getEntity(), Response.CHART);
	@SuppressWarnings("rawtypes")
	HashMap map = JacksonUtil.readValue(json, HashMap.class);
	System.out.println(map);

	url = "http://localhost:10000/api/v1/userinfo/checkAccessToken?access_token=" + map.get("access_token");

	System.out.println(url);
	System.out.println(EntityUtils.toString(
			new HttpClientFactory().execute(new MyHttpConfig().method(HttpMethods.GET).uri(url)).getEntity(),
			Response.CHART));

}                                  
<b>注：使用httpclient测试。</b>
                                  </pre>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                           </li>
                           
                           
                       </ul>
                   </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>